﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Elight.WebApi.Responses;
using Elight.Infrastructure.Helpers;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Authorization;

namespace Elight.WebApi.Controllers
{
    /// <summary>
    /// 控制器基类。
    /// </summary>
    [Authorize]
    //[EnableCors("MyPolicy")]
    public class BaseController : Controller
    {
        /// <summary>
        /// 成功操作。
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        protected IActionResult Success(string message = "恭喜您，操作成功。", object data = null)
        {
            return Content(new AjaxResult(ResultTypes.Success, message, data).ToJson());
        }

        /// <summary>
        /// 错误操作。
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        protected IActionResult Error(string message = "对不起，操作失败。", object data = null)
        {
            return Content(new AjaxResult(ResultTypes.Error, message, data).ToJson());
        }

        /// <summary>
        /// 警告操作。
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        protected IActionResult Warning(string message, object data = null)
        {
            return Content(new AjaxResult(ResultTypes.Warning, message, data).ToJson());
        }

        /// <summary>
        /// 信息操作。
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        protected IActionResult Info(string message, object data = null)
        {
            return Content(new AjaxResult(ResultTypes.Info, message, data).ToJson());
        }
    }
}
